package snakesladders.domain;

import java.util.Observer;

import minidraw.boardgame.BoardGameObserver;
import snakesladers.view.Constant;

public class GameImpl implements Game {
	private int die = 1;
	private BoardGameObserver<Square> observer;
	private Square tokenSquare = new Square(1);
	
	@Override
	public void rollDie() {
		die = (int) (Math.random()*6+1);
		observer.propChangeEvent(Constant.diePropName);
	}

	@Override
	public int getDieValue() {
		return die;
	}

	@Override
	public void addObserver(BoardGameObserver<Square> observer) {
		this.observer = observer;
	}

	@Override
	public boolean move(int player, Square fromSquare, Square toSquare) {
		System.out.println("Moving to "+toSquare.index());
		tokenSquare = toSquare;
		observer.pieceMovedEvent(fromSquare, toSquare);
		return true;
	}
}
